package com.flx.application.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.flx.application.dao.TUserMapper;
import com.flx.application.model.TUser;
import com.flx.sys.jwt.JwtTokenUtil;

@RestController
@RequestMapping("/tUser")
public class UserController {
	
	
	@Autowired
	private JwtTokenUtil jwtTokenUtil;
	
	@Autowired
	private TUserMapper mapper;

	@GetMapping("/me")
	public Object getCurrentUser(Authentication user, HttpServletRequest request) throws Exception {
		String hender = request.getHeader("Authorization");
		String token = StringUtils.substringAfter(hender, "bearer ");
		String claims = jwtTokenUtil.getUsernameFromToken(token);
		System.out.println(claims);
		return user;
	}
	@GetMapping("/find")
	public List<TUser> findAll(){
		return mapper.selectAll();
		
	}

}
